﻿using UnityEngine;

namespace Core.Res
{
    // ReSharper disable once InconsistentNaming
    public partial class WXLoader
    {
        public class Batch : LoadAwaiter
        {
            private int mTotalCnt = 0;

            public Batch(WXLoader loader) : base(loader)
            {
            }

            public override void Start()
            {
                State = ELoadState.Loading;
                mTotalCnt = Rely.Count;
            }

            public override void Update()
            {
                var curr_cnt = Rely.Count;
                Progress = Mathf.Clamp01((mTotalCnt - curr_cnt) * 1.0f / mTotalCnt);

                if (Progress == 1)
                {
                    State = ELoadState.Complete;
                }
            }


            public override void Finish()
            {
                Awaiter?.SetResult();
                Awaiter = null;
            }


            public void Dispose()
            {
                State = ELoadState.Invalid;
            }
        }
    }
}
